package android.trabalho;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RatingBar;
import android.widget.TextView;

public class ListaBaseAdapter extends BaseAdapter {

	private static ArrayList<Posto> searchArrayList;
	private Context context;
	private LayoutInflater mInflater;

	public ListaBaseAdapter(Context context, ArrayList<Posto> results) {
		this.context = context;
		searchArrayList = results;

	}

	public int getCount() {
		return searchArrayList.size();
	}

	public Object getItem(int position) {
		return searchArrayList.get(position);
	}

	public long getItemId(int position) {
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		mInflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.listcustom, null);
			holder = new ViewHolder();
			holder.txtNome = (TextView) convertView.findViewById(R.id.nome);
			holder.txtCombustivel = (TextView) convertView
					.findViewById(R.id.combustivel);
			holder.txtValor = (TextView) convertView.findViewById(R.id.valor);
			holder.rtBar = (RatingBar) convertView.findViewById(R.id.satisf_bar);

			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		holder.txtNome.setText(searchArrayList.get(position).getNome());
		holder.txtCombustivel.setText(searchArrayList.get(position)
				.getCombustivel());
		holder.txtValor.setText(String.valueOf(searchArrayList.get(position)
				.getValor()));
		holder.rtBar.setRating(searchArrayList.get(position).getSatisfacao());

		return convertView;
	}

	static class ViewHolder {
		TextView txtNome;
		TextView txtCombustivel;
		TextView txtValor;
		RatingBar rtBar;
	}

}
